package mysql_utils

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

func ConnectToDB(host string, port int, user, password, dbname string) (*sql.DB, error) {
	connectionString := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", user, password, host, port, dbname)

	db, err := sql.Open("mysql", connectionString)
	if err != nil {
		return nil, err
	}

	err = db.Ping()
	if err != nil {
		return nil, err
	}

	return db, nil
}

func ExecuteSQL(db *sql.DB, query string) (sql.Result, error) {
	result, err := db.Exec(query)
	if err != nil {
		return nil, err
	}
	return result, nil
}

